/**
 */
package org.mro.grib.model.files.firstEdition.sections.impl;

import java.nio.ByteBuffer;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.mro.grib.core.Grib1Constantes;
import org.mro.grib.model.files.firstEdition.sections.BitMapSection;
import org.mro.grib.model.files.firstEdition.sections.SectionsPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Bit Map Section</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BitMapSectionImpl#getStartOffset <em>Start Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BitMapSectionImpl#getEndOffset <em>End Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BitMapSectionImpl#getLength <em>Length</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BitMapSectionImpl#getNumberOfUnusedBitsAtEndOfSection3 <em>Number Of Unused Bits At End Of Section3</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BitMapSectionImpl#getReferenceTable <em>Reference Table</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.BitMapSectionImpl#getDataOffset <em>Data Offset</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BitMapSectionImpl extends EObjectImpl implements BitMapSection {
	/**
	 * The default value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long START_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected long startOffset = START_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long END_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected long endOffset = END_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected static final int LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected int length = LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #getNumberOfUnusedBitsAtEndOfSection3() <em>Number Of Unused Bits At End Of Section3</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNumberOfUnusedBitsAtEndOfSection3()
	 * @generated
	 * @ordered
	 */
	protected static final byte NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getNumberOfUnusedBitsAtEndOfSection3() <em>Number Of Unused Bits At End Of Section3</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNumberOfUnusedBitsAtEndOfSection3()
	 * @generated
	 * @ordered
	 */
	protected byte numberOfUnusedBitsAtEndOfSection3 = NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3_EDEFAULT;

	/**
	 * The default value of the '{@link #getReferenceTable() <em>Reference Table</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferenceTable()
	 * @generated
	 * @ordered
	 */
	protected static final short REFERENCE_TABLE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getReferenceTable() <em>Reference Table</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferenceTable()
	 * @generated
	 * @ordered
	 */
	protected short referenceTable = REFERENCE_TABLE_EDEFAULT;

	/**
	 * The default value of the '{@link #getDataOffset() <em>Data Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long DATA_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getDataOffset() <em>Data Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataOffset()
	 * @generated
	 * @ordered
	 */
	protected long dataOffset = DATA_OFFSET_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BitMapSectionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SectionsPackage.Literals.BIT_MAP_SECTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getStartOffset() {
		return startOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartOffset(long newStartOffset) {
		long oldStartOffset = startOffset;
		startOffset = newStartOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__START_OFFSET, oldStartOffset, startOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getEndOffset() {
		return endOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndOffset(long newEndOffset) {
		long oldEndOffset = endOffset;
		endOffset = newEndOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__END_OFFSET, oldEndOffset, endOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getLength() {
		return length;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLength(int newLength) {
		int oldLength = length;
		length = newLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__LENGTH, oldLength, length));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getNumberOfUnusedBitsAtEndOfSection3() {
		return numberOfUnusedBitsAtEndOfSection3;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setNumberOfUnusedBitsAtEndOfSection3(byte newNumberOfUnusedBitsAtEndOfSection3) {
		byte oldNumberOfUnusedBitsAtEndOfSection3 = numberOfUnusedBitsAtEndOfSection3;
		numberOfUnusedBitsAtEndOfSection3 = newNumberOfUnusedBitsAtEndOfSection3;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3, oldNumberOfUnusedBitsAtEndOfSection3, numberOfUnusedBitsAtEndOfSection3));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public short getReferenceTable() {
		return referenceTable;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setReferenceTable(short newReferenceTable) {
		short oldReferenceTable = referenceTable;
		referenceTable = newReferenceTable;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__REFERENCE_TABLE, oldReferenceTable, referenceTable));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getDataOffset() {
		return dataOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDataOffset(long newDataOffset) {
		long oldDataOffset = dataOffset;
		dataOffset = newDataOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.BIT_MAP_SECTION__DATA_OFFSET, oldDataOffset, dataOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				return getStartOffset();
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				return getEndOffset();
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				return getLength();
			case SectionsPackage.BIT_MAP_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3:
				return getNumberOfUnusedBitsAtEndOfSection3();
			case SectionsPackage.BIT_MAP_SECTION__REFERENCE_TABLE:
				return getReferenceTable();
			case SectionsPackage.BIT_MAP_SECTION__DATA_OFFSET:
				return getDataOffset();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				setStartOffset((Long)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				setEndOffset((Long)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				setLength((Integer)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3:
				setNumberOfUnusedBitsAtEndOfSection3((Byte)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__REFERENCE_TABLE:
				setReferenceTable((Short)newValue);
				return;
			case SectionsPackage.BIT_MAP_SECTION__DATA_OFFSET:
				setDataOffset((Long)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				setStartOffset(START_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				setEndOffset(END_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				setLength(LENGTH_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3:
				setNumberOfUnusedBitsAtEndOfSection3(NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__REFERENCE_TABLE:
				setReferenceTable(REFERENCE_TABLE_EDEFAULT);
				return;
			case SectionsPackage.BIT_MAP_SECTION__DATA_OFFSET:
				setDataOffset(DATA_OFFSET_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SectionsPackage.BIT_MAP_SECTION__START_OFFSET:
				return startOffset != START_OFFSET_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__END_OFFSET:
				return endOffset != END_OFFSET_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__LENGTH:
				return length != LENGTH_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3:
				return numberOfUnusedBitsAtEndOfSection3 != NUMBER_OF_UNUSED_BITS_AT_END_OF_SECTION3_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__REFERENCE_TABLE:
				return referenceTable != REFERENCE_TABLE_EDEFAULT;
			case SectionsPackage.BIT_MAP_SECTION__DATA_OFFSET:
				return dataOffset != DATA_OFFSET_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (startOffset: "); //$NON-NLS-1$
		result.append(startOffset);
		result.append(", endOffset: "); //$NON-NLS-1$
		result.append(endOffset);
		result.append(", length: "); //$NON-NLS-1$
		result.append(length);
		result.append(", numberOfUnusedBitsAtEndOfSection3: "); //$NON-NLS-1$
		result.append(numberOfUnusedBitsAtEndOfSection3);
		result.append(", referenceTable: "); //$NON-NLS-1$
		result.append(referenceTable);
		result.append(", dataOffset: "); //$NON-NLS-1$
		result.append(dataOffset);
		result.append(')');
		return result.toString();
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.sections.BitMapSection#initialise(java.nio.ByteBuffer)
	 */
	@Override
	public void initialise(ByteBuffer buffer) {
		numberOfUnusedBitsAtEndOfSection3 = buffer.get();
		referenceTable = buffer.getShort();
		dataOffset = startOffset + Grib1Constantes.NB_OCTETS_INT_GRIB + buffer.position();
	}
	
} //BitMapSectionImpl
